﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;

using ProjectBase.Core;

namespace $safeprojectname$.Services
{
    /// <summary>
    ///     Entity Article.
    /// </summary>
    [Serializable]
    public class Article : Persistent<int>, ITVSource
    {
        #region members

        private string _articleCategoryCode;
        private string _articleGroupCode;

        #endregion members

        private int? _categoryId;
        private int? _groupId;
        public virtual string Text { get; set; }
        public virtual string HtmlText { get; set; }

        public virtual ArticleCategory ArticleCategory { get; set; }
        public virtual ArticleGroup ArticleGroup { get; set; }

        public virtual DateTime CreationDate { get; set; }
        public virtual DateTime LastUpdateDate { get; set; }
        public virtual DateTime? ReleaseDate { get; set; }

        public virtual bool IsVisible { get; set; }
        public virtual bool ShowComment { get; set; }

        #region virtual

        public virtual string ArticleCategoryCode
        {
            get
            {
                if (_articleCategoryCode.IsEmpty()
                    && ArticleCategory.Is())
                {
                    return ArticleCategory.Code;
                }
                return _articleCategoryCode;
            }
            set { _articleCategoryCode = value; }
        }

        public virtual string ArticleGroupCode
        {
            get
            {
                if (_articleGroupCode.IsEmpty()
                    && ArticleGroup.Is())
                {
                    return ArticleGroup.Code;
                }
                return _articleGroupCode;
            }
            set { _articleGroupCode = value; }
        }

        #endregion virtual

        #region override abstract

        public override string ToDisplay()
        {
            return Code + " - " + Title;
        }

        protected override string GetDomainObjectSignature()
        {
            return Code;
        }

        #endregion override abstract

        #region ITVSource Members

        public virtual string Code { get; set; }
        public virtual string Title { get; set; }
        public virtual string Description { get; set; }

        int ITVSource.ArticleCategoryId
        {
            get { return ArticleCategoryId; }
            set { ArticleCategoryId = value; }
        }
        int ITVSource.ArticleGroupId
        {
            get { return ArticleGroupId; }
            set { ArticleGroupId = value; }
        }
        int ITVSource.Year { get { return Year; } }
        int ITVSource.Month { get { return Month; } }

        protected virtual int ArticleCategoryId
        {
            get { return _categoryId ?? ArticleCategory.Id(); }
            set { _categoryId = value; }
        }
        protected virtual int ArticleGroupId
        {
            get { return _groupId ?? ArticleGroup.Id(); }
            set { _groupId = value; }
        }
        protected virtual int Year
        {
            get { return ReleaseDate.Value.Year; }
        }
        protected virtual int Month
        {
            get { return ReleaseDate.Value.Month; }
        }

        #endregion ITVSource Members
    }
}